//
//  DetailDiseaseInfoViewController.m
//  棒棒哒
//
//  Created by rimi on 15/8/5.
//  Copyright (c) 2015年 rimi. All rights reserved.
//

#import "DetailDiseaseInfoViewController.h"
#import "DetailDepartmentViewController.h"
#import "config.h"
@interface DetailDiseaseInfoViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic ,strong)NSMutableArray     *diseaseArray;
@property (nonatomic ,strong)UITableView        *tableView;
@property (nonatomic ,strong)UISearchController *searchControll;
@end

@implementation DetailDiseaseInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeUserInterface];
    [self netWorkRequest];
}

-(void)initializeDataSource
{
    
    
}



-(void)initializeUserInterface
{
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"加载中..";
    
}

-(void)loadAfterNetworkRequest
{
    self.title = @"疾病信息";
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,NAVST_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - NAVST_HEIGHT ) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource =self;
    [self.view addSubview:_tableView];
    
    _searchControll = [[UISearchController alloc]initWithSearchResultsController:nil];
    [_searchControll.searchBar sizeToFit];
    _tableView.tableHeaderView = _searchControll.searchBar;
    UILabel *label = [[UILabel alloc]init];
    
    if (_diseaseArray.count) {
        label.text = @"";
    }else{
        label.frame = CGRectMake(0, 0, _tableView.bounds.size.width, 40);
        label.textAlignment = NSTextAlignmentCenter;
        label.text = @"没有该找到该疾病";
    }
    
    _tableView.tableFooterView = label;
    self.definesPresentationContext = YES;
//    [_tableView reloadData];

    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
    return _diseaseArray.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DEPARTMENTSCELL"];
    if (!cell) {
        cell = [[UITableViewCell alloc]init];
    }
    cell.textLabel.text = _diseaseArray[indexPath.row][@"name"];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailDepartmentViewController *detailDepartMent = [[DetailDepartmentViewController alloc]init];
    detailDepartMent.departmentId = _diseaseArray[indexPath.row][@"id"];
    
    [self.navigationController pushViewController:detailDepartMent animated:YES];


}



-(void)netWorkRequest
{
    NSDictionary *dic = @{@"apikey":APIKEY,
                          @"did":_departmentID,
                          @"pid":_originID
                          };
//    NSLog(@"did = %@\npid = %@",_departmentID,_originID);
    [NetRequest GET:@"http://api.1ccf.com/disease/list" parameters:dic success:^(id responseObject) {
//        NSLog(@"%@",responseObject);
        _diseaseArray = [responseObject[@"yi18"] mutableCopy];
        [self loadAfterNetworkRequest];
    } failure:^(NSError *error) {
        NSLog(@"%@",error.localizedDescription);
    }];


    
    
    
    
    
}





@end
